package handlers

import (
	"InstantImage/tcpService"
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

func getDeleteHandler(service *tcpService.TcpService) gin.HandlerFunc {
	return func(c *gin.Context) {
		dialDEL, _ := service.DelPool.Get()
		defer service.DelPool.Put(dialDEL)

		key := c.Param("key")

		_, err := dialDEL.Write([]byte(fmt.Sprintf("del %s;", key)))
		if err != nil {
			//c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to send request to TCP server"})
			c.HTML(http.StatusNotFound, "404.html", gin.H{"error": "Failed to send request to TCP server"})
			return
		}
	}
}
